package com.itheima.reggie.exception;

import com.itheima.reggie.config.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public R exceptionHandler(Exception e){
            e.printStackTrace();
             return R.error("网络异常");
    }

    @ExceptionHandler(NameExistsException.class)
    public R exceptionHandler(NameExistsException e){
            e.printStackTrace();
            return R.error("用户名已经重复");
    }
    @ExceptionHandler(CustomerException.class)
    public R exceptionHandler(CustomerException e){
            e.printStackTrace();
            return R.error(e.getMessage());
    } @ExceptionHandler(CodeException.class)
    public R exceptionHandler(CodeException e){
            e.printStackTrace();
            return R.error(e.getMessage());
    }

}
